pub mod tracer;


mod formatter;
mod curly_bracket_map_flag;
mod reader;
pub mod deserializer;

pub mod error;
pub mod serializer;


pub mod map;
pub mod bytes;
pub mod value;




use crate::error::Result;
use serde::ser::{Serialize}
;
use serde::de::Deserialize;
use crate::formatter::CompactFormatter;
use crate::deserializer::from_trait;
use crate::serializer::Serializer;

pub mod skip_ser_func {
    use std::collections::HashMap;
    pub fn slice<T>(v: &[T]) -> bool
    {
        v.is_empty() 
    }
    pub fn hashmap<K, V, S>(v: &HashMap<K, V, S>) -> bool 
    {
        v.is_empty()
    }
    pub fn str(v: &str) -> bool {
        v.is_empty()
    }
}


//1. to_string
//TODO: 2. to_vec
//TODO: 3. to_writer

pub fn to_string<T>(v: &T) -> Result<String> 
where 
    T: ?Sized + Serialize,
{
    let vec = to_vec(v)?;
    let string = unsafe {
        String::from_utf8_unchecked(vec)
    };
    Ok(string)
}

pub fn to_vec<T>(v: &T) -> Result<Vec<u8>> 
where T: ?Sized + Serialize
{
    let mut w = Vec::<u8>::with_capacity(128);
    let mut s = Serializer::with_formatter(&mut w, CompactFormatter{});
    v.serialize(&mut s)?;
    Ok(w)
}




pub fn from_str<'a, T>(s: &'a str) -> Result<T> 
where 
    T: Deserialize<'a>,
{
    from_trait(reader::SliceRead::new(s.as_bytes()))
}

pub fn from_slice<'a, T>(s: &'a [u8]) -> Result<T> 
where   
    T: Deserialize<'a> ,
{
    from_trait(reader::SliceRead::new(s))
}
    


#[cfg(test)]
mod test {
    #[test]
    fn from(){
        //let gtp_str =b"X01=1";
        //let t = <map::Map>::from_slice(gtp_str);
    }
}

